package com.hdoit.ares.logical.policy.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.hdoit.ares.logical.policy.dao.IListPolicyDao;
import com.hdoit.ares.logical.policy.mapper.ListPolicyMapper;
import com.hdoit.ares.logical.policy.model.ListPolicy;
import com.hdoit.ares.logical.viewmodel.policy.ListPolicySearch;
import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.enums.OrderEnum;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.FinderExpressionFactory;
/**
 * @author      caochengmeng
 * @email       
 * @createtime  2018年01月18日 00:52:43
 * @comment
 */
@Component
public class ListPolicyDaoImpl extends SuperDao<ListPolicy> implements IListPolicyDao{
	
	private ListPolicyMapper listPolicyMapper;
	public ListPolicyMapper getListPolicyMapper() {
		return listPolicyMapper;
	}
	@Resource
	public void setListPolicyMapper(ListPolicyMapper listPolicyMapper) {
		this.listPolicyMapper = listPolicyMapper;
	}

	@Override
	public List<ListPolicy> queryAllAccidentPolicy(String customerId) {
		return listPolicyMapper.queryAllAccidentPolicy(customerId);
	}

	@Override
	public List<ListPolicy> queryAllCarPolicy(String customerId) {
		return listPolicyMapper.queryAllCarPolicy(customerId);
	}
	
	@Override
	public ListPolicy queryFanhuaAccident(String customerId, String oid) {
		return listPolicyMapper.queryFanhuaAccident(customerId, oid);
	}
	
	@Override
	public ListPolicy queryZhonganAccident(String customerId, String oid) {
		return listPolicyMapper.queryZhonganAccident(customerId, oid);
	}
	
	@Override
	public ListPolicy queryFanhuaAccidentDetail(String oid) {
		return listPolicyMapper.queryFanhuaAccidentDetail(oid);
	}
	@Override
	public ListPolicy queryZhonganAccidentDetail(String oid) {
		return listPolicyMapper.queryZhonganAccidentDetail(oid);
	}

	@Override
	public ListPolicy queryFanhuaCarDetail(String oid) {
		return listPolicyMapper.queryFanhuaCarDetail(oid);
	}
	@Override
	public ListPolicy queryZhonganCarDetail(String oid) {
		return listPolicyMapper.queryZhonganCarDetail(oid);
	}
	@Override
	public List<ListPolicy> queryList(ListPolicySearch search,PagerModel pagerModel){
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(ListPolicy.class);
						
		if(!StringUtils.isEmpty(search.getSigns())){
			finderExpression.andEq("signs", search.getSigns());
		}
		if(!StringUtils.isEmpty(search.getProductName())){
			finderExpression.andWhere("productName like #{productName}")
			  .setParam("productName", "%"+search.getProductName()+"%");
		}
		if(!StringUtils.isEmpty(search.getOid())){
			finderExpression.andWhere("oid like #{oid}")
			  .setParam("oid", "%"+search.getOid()+"%");
		}
		if(search.getStartDate()!=null){
			finderExpression.andWhere("TIMESTAMPDIFF(SECOND,#{startDate},startDate)>=0")
				  .setParam("startDate", search.getStartDate());
		}
		if(search.getEndDate()!=null){
			finderExpression.andWhere("TIMESTAMPDIFF(SECOND,#{endDate},shareBrokerage.endDate)<=0")
				  .setParam("endDate", search.getEndDate());
		}
		if(search.getCreateDate()!=null){
			finderExpression.andWhere("TIMESTAMPDIFF(SECOND,#{createDate},createDate)<=0")
				  .setParam("createDate", search.getCreateDate());
		}
		finderExpression.addOrder("createDate", OrderEnum.desc);
		
		if(pagerModel == null){
			return queryList(finderExpression, search);
		}		
		return queryList(finderExpression, search,pagerModel);
	}
	@Override
	public int queryCountWeekPolicys(String customerId) {
		return listPolicyMapper.queryCountWeekPolicys(customerId);
	}
	@Override
	public int queryCountMonthPolicys(String customerId) {
		return listPolicyMapper.queryCountMonthPolicys(customerId);
	}
}